//
//  AddContactViewController.m
//  Weiweiyunshi
//
//  Created by 张旭峰 on 2017/2/14.
//  Copyright © 2017年 王译. All rights reserved.
//

#import "AddContactViewController.h"
#import "PYSearch.h"
#import "AddContactTableViewCell.h"
#import "QRCodeViewController.h"
#import "AddressfriendTableViewController.h"
#import "LoginModel.h"
#import "SearchModel.h"
#import "ResultViewController.h"
#import "VVNavigationController.h"
//搜索控制器
#import "SearchViewController.h"
@interface AddContactViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchControllerDelegate>
{
    

}
@property(nonatomic,weak)UITableView* tableView;
@property(nonatomic,strong)UISearchController * searchController;
@end

@implementation AddContactViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title =@"添加联系人";
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"header_back_icon"] style:UIBarButtonItemStyleDone target:self action:@selector(pop)];
    self.navigationItem.leftBarButtonItem = backItem;
    
     self.view.backgroundColor = [UIColor colorWithRed:239 green:239 blue:244];
    [self setupUI];
    self.tableView.rowHeight=UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight=200;
   [self.tableView registerNib:[UINib nibWithNibName:@"AddContactTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell1"];

}
-(void)pop
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)setupUI
{
    _searchController =[[UISearchController alloc]initWithSearchResultsController:nil];
    _searchController.delegate = self;
    _searchController.dimsBackgroundDuringPresentation = NO;
    //    _searchController.obscuresBackgroundDuringPresentation = NO;
    _searchController.hidesNavigationBarDuringPresentation = NO;
    self.definesPresentationContext = YES;
    [self.view addSubview:_searchController.searchBar];
    
    [_searchController.searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(-10);
        make.right.offset(10);
        make.height.equalTo(@30);
        make.top.offset(80);
    }];
    UITableView *tableView= [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tableView.dataSource = self;
    [self.view addSubview: tableView];
    self.tableView = tableView;

    self.tableView.delegate=self;
    self.tableView.dataSource = self;
    
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(120);
        make.left.right.offset(0);
            make.bottom.offset(0);
    }];
    

}

-(void)presentSearchController:(UISearchController *)searchController
{
    NSLog(@"------->搜索控制器跳转");
    SearchViewController *searchVc = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchVc animated:YES];
    //    [searchBar resignFirstResponder];
    //    return YES;
}








-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.001;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AddContactTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"forIndexPath:indexPath];
    
    if(indexPath.row==0)
    {
        cell.leftImage.image = [UIImage imageNamed:@"shaoyishao"];
        cell.toplabel.text = @"扫一扫";
        cell.bottomlabel.text = @"扫描二维码名片";
        
    }else{
        cell.leftImage.image = [UIImage imageNamed:@"Contact"];
        cell.toplabel.text = @"手机联系人";
        cell.bottomlabel.text = @"添加通讯录中的联系人";

    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
   
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
        
        

    if(indexPath.row ==0)
    {
    QRCodeViewController * VC1 = [[QRCodeViewController alloc]init];
    [self.navigationController pushViewController:VC1 animated:NO];
    }
    else{
        AddressfriendTableViewController * VC2 = [[AddressfriendTableViewController alloc]init];
        [self.navigationController pushViewController:VC2 animated:NO];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
